package benny.ApkposStore.Activity;

import java.text.SimpleDateFormat;
import java.util.List;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import benny.ApkposStore.R;
import benny.ApkposStore.db.OrderTableNew;
import benny.ApkposStore.model.OrderNew;
import benny.ApkposStore.proto.Basic.Floor_tables;
import benny.ApkposStore.utils.ApkUntils;

//import com.tencent.elife.asyn.BaseManager;
//import com.tencent.elife.asyn.Command;
//import com.tencent.elife.asyn.DataResponse;

public class DataTestActivity extends Activity {
	protected List<Floor_tables> floorlist;
	private SimpleDateFormat sdf;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ApkUntils.fullscreen(this);
		setContentView(R.layout.datatest);
		sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		updateresponse();
		findViewById(R.id.btn_test_login).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						Log.i("test", "login test click");
					}
				});

		findViewById(R.id.btn_test_query_basic_update).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						Log.i("test", "query basic update test click");
					}
				});

		findViewById(R.id.btn_test_query_basic).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
//						DataResponse<BasicResponse> response = new DataResponse<BasicResponse>() {
//							@Override
//							public void onResponse(BasicResponse result,
//									int arg1, Object arg2, Object arg3) {
//
//								int cnt = result.getFloorTablesCount();
//								List<Floor_tables> floors = result
//										.getFloorTablesList();
//								Log.i("test", "floor table count:" + cnt);
//								System.out.println("-----" + floors);
//								/*
//								 * for (Iterator iterator = floors.iterator();
//								 * iterator .hasNext();) { Floor_tables
//								 * floor_tables = (Floor_tables) iterator
//								 * .next(); System.out.println("-----" +
//								 * floor_tables.getRfnmVar()); }
//								 */
//
//							}
//
//							@Override
//							public void onError(final int errorCode,
//									final String errorInfo,
//									final Command<?> cmd,
//									final BaseManager manager) {
//								Log.e("test", errorInfo);
//							}
//						};
//						DataManager.instance().queryBasic(response);
						Log.i("test", "query basic test click");
					}

				});

		findViewById(R.id.btn_finish_test).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						finish();
					}
				});

		findViewById(R.id.btn_order_create_test).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// insert

						OrderTableNew orderTable = new OrderTableNew(
								getApplicationContext());
						OrderNew order = new OrderNew();
						order.setId(0);
						order.setOrderid(100 + "");
						order.setOrder_pay(10);
						order.setPeople_num(6);
						order.setTable_num(101);
						String date = sdf.format(new java.util.Date());
						order.setOpen_time(date);
						order.setDic_charge(34);
						order.setTs(11111);
						order.setCashuser("wwwww");
						if (orderTable.insert(order) != -1) {
							Log.i("insert order", "insert ok");
						} else {
							Log.e("insert order", "insert failed");
						}
						order.setOrderid(200 + "");
						orderTable.insert(order);

						// query
						String selection = null;
						String selectionArgs[] = { null };
						Cursor curSor = orderTable.getCurSor(selection,
								selectionArgs);
						int rowId = 0;
						while (curSor.moveToNext()) {
							int idx = curSor
									.getColumnIndex(OrderTableNew.CORDER_PAY);
							int val = curSor.getInt(idx);
							Log.e("query order", "order pay:" + val);

							idx = curSor.getColumnIndex(OrderTableNew.CID);
							rowId = curSor.getInt(idx);
						}
						curSor.close();

						// del
						if (orderTable.delete(rowId)) {
							Log.i("delete order", "delete ok");
						} else {
							Log.e("delete order", "delete failed");
						}
					}
				});

	}

	private void updateresponse() {
//		DataResponse<BasicResponse> response = new DataResponse<BasicResponse>() {
//			@Override
//			public void onResponse(BasicResponse result, int arg1, Object arg2,
//					Object arg3) {
//				floorlist = result.getFloorTablesList();
//				System.out.println("-----" + floorlist);
//				/*
//				 * for (Iterator iterator = floors.iterator(); iterator
//				 * .hasNext();) { Floor_tables floor_tables = (Floor_tables)
//				 * iterator .next(); System.out.println("-----" +
//				 * floor_tables.getRfnmVar()); }
//				 */
//
//			}
//
//			@Override
//			public void onError(final int errorCode, final String errorInfo,
//					final Command<?> cmd, final BaseManager manager) {
//				Log.e("test", errorInfo);
//			}
//		};
//		DataManager.instance().queryBasic(response);

	}
}
